package com.xu.controller;

import com.xu.mapper.EvaluateMapper;
import com.xu.mapper.OrderMapper;
import com.xu.pojo.Evaluate;
import com.xu.pojo.Order;
import com.xu.pojo.Product;
import com.xu.service.ProductService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class EvaluateController {

    @Autowired
    private ProductService productService;

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private EvaluateMapper evaluateMapper;

    @RequestMapping("/toEvaluate/{id}")
    public String toEvaluate(@PathVariable("id")int id, Model model)
    {
        Order order = orderMapper.queryOrderByIid(id);
        model.addAttribute("order", order);
        return "user/evaluate";
    }

    @RequestMapping("/addEvaluate")
    public String addEvaluate(Evaluate evaluate)
    {
        evaluateMapper.insertEvaluate(evaluate);
        Order order = orderMapper.queryOrderByIid(evaluate.getOid());
        order.setIsEvaluate(1);
        orderMapper.updOorder(order);
        return "redirect:/toDashboardUser2";
    }

    @RequestMapping("/toEvaluates")
    public String toEvaluates(Model model)
    {
        List<Evaluate> evaluates = evaluateMapper.queryAllEvaluate();
        model.addAttribute("evaluates", evaluates);
        return "admin/evaluates";
    }
}
